package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.cache.GuiGuCache;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user")
@SuppressWarnings({"all"})
public class UserInfoApiController {

    @Autowired
    private UserInfoService userInfoService;


    /**
     * /api/user/userInfo/getUserInfoVo/{userId}
     * @param userId
     * @return
     */
   // @GuiGuCache
    @GetMapping("/userInfo/getUserInfoVo/{userId}")
    public Result<UserInfoVo> getUserInfoVo(@PathVariable Long userId) {
        UserInfoVo userInfoVo = userInfoService.getUserInfoById(userId);
        return Result.ok(userInfoVo);
    }

    // /api/user/userInfo/userIsPaidTrack/{userId}/{albumId}

    /**
     * 即判断用户是否已经购买专辑或者专辑内的声音
     * notice ： 此时支持用户整张专辑购买、或者专辑某一个声音单独购买
     * Map<Long,Integer> == {trackId?1:0} 1 表示已购买 0 表示未购买
     * @param userId
     * @param albumId
     * @param checkedTrackIds
     * @return
     */
    @PostMapping("/userInfo/userIsPaidTrack/{userId}/{albumId}")
    public Result<Map<Long,Integer>> userIsPaidTrack(@PathVariable Long userId,
                                                     @PathVariable Long albumId,
                                                     @RequestBody List<Long> checkedTrackIds){

        Map<Long,Integer> checkedTrackIdsMap =userInfoService.userIsPaidTrack(userId,albumId,checkedTrackIds);
        return Result.ok(checkedTrackIdsMap);
    }


}

